<?php
/*************************************************************************************
 *
 *	FileName: ResourceControl.php
 *	Desc    : This file contains how to control the version of the static resources
 *	Author  : Seal
 *	Date    : 2010-8-1
 *
 *************************************************************************************/

	// describe a compound resource which is composed of more than one resources
	$compoundResource = array(
		'jquery.js.php' => array(
			"lib/jquery-1.4.2.min.js",
			"lib/jquery.blockUI.js",
			"lib/jquery.validate.js" ),
		'add_shop.js.php' => array(
			"add_shop.js",
			"lib/jquery.ui.datepicker.js",
			"lib/jquery.ui.core.js" ),
		'common.js.php' => array(
			 "popup_login.js",
			 "popup_report.js",
			 "popup_flower_egg.js",
			 "popup_collect.js",
			 "popup_friend.js",
			 "popup_msg.js",
			 "common.js",
			 'lib/jquery.lightbox-0.5.min.js' ),
		'product_info.js.php' => array(
			 "add_review.js",
			 "product_info.js" ),
		'shop_info.js.php' => array( "popup_login.js",
			"add_review.js",
			"shop_info.js" ),
		'add_shop.css.php' => array(
			 "add_shop.css",
			 "jquery-ui-1.7.2.custom.css" ),
		'product_info.css.php' => array(
			 "add_review.css",
			 "product_info.css" ),
		'shop_info.css.php' => array(
			 "add_review.css",
			 "shop_info.css" ),
		'global.css.php' => array(
			'global.css',
			'jquery.lightbox-0.5.css'),
		'user_setting.js.php' => array(
			'user_setting.js',
			'lib/jquery.Jcrop.min.js'),
		'user_list_create.js.php' => array(
			'user_list_create.js',
			'lib/jquery.tools.min.js' )
	);
	
	// Decide whether we have to refresh the resource for a new version
	function EDPGetResourceVersion( $pageBase, $type = 'js' )
	{
		global $compoundResource;
		
		$resourcePath = STATIC_DIR . $type . '/'; 
		$version = '';
		
		if( !array_key_exists($pageBase, $compoundResource) ){
			$stat = stat( $resourcePath . $pageBase );
			$lastModifiedDate = $stat['mtime'];
		} else {
			$lastModifiedDate = '';
			$files = $compoundResource[$pageBase];
			foreach( $files as $fileName ){
				$stat = stat( $resourcePath . $fileName );
				$lastModifiedDate .= $stat['mtime'];
			}
			$stat = stat( $resourcePath . $pageBase );
			$lastModifiedDate .= $stat['mtime'];
		}
		
		return md5( $lastModifiedDate );
	}


?>